import request from '@/utils/request'

// 查询入住管理列表
export function listManagement(query) {
  return request({
    url: '/system/management/list',
    method: 'get',
    params: query
  })
}

// 查询入住管理详细
export function getManagement(id) {
  return request({
    url: '/system/management/' + id,
    method: 'get'
  })
}

// 新增入住管理
export function addManagement(data) {
  return request({
    url: '/system/management',
    method: 'post',
    data: data
  })
}

// 修改入住管理
export function updateManagement(data) {
  return request({
    url: '/system/management',
    method: 'put',
    data: data
  })
}

// 删除入住管理
export function delManagement(ids) {
  return request({
    url: '/system/management/' + ids,
    method: 'delete'
  })
}

// 完整入住申请流程
export function completeApplication(data) {
  return request({
    url: '/system/management/complete',
    method: 'post',
    data: data
  })
}

// 启动入住申请工作流
export function startWorkflow(checkInManagementId) {
  return request({
    url: '/system/management/startWorkflow',
    method: 'post',
    params: { checkInManagementId }
  })
}

// 处理工作流任务
export function handleTask(taskId, opinion, auditStatus, checkInManagementId, stepNo) {
  return request({
    url: '/system/management/handleTask',
    method: 'post',
    params: { taskId, opinion, auditStatus, checkInManagementId, stepNo }
  })
}

// 查询工作流任务列表
export function listWorkflowTasks(query) {
  return request({
    url: '/system/management/workflowTasks',
    method: 'get',
    params: query
  })
}

// 查询审批记录
export function listApprovalRecords(businessId) {
  return request({
    url: '/system/management/approvalRecords',
    method: 'get',
    params: { businessId }
  })
}

// 🔥 第二步：保存评估草稿（JSON格式）
export function saveAssessmentDraft(checkInManagementId, assessmentDraftJson) {
  return request({
    url: '/system/management/saveAssessmentDraft',
    method: 'post',
    params: { checkInManagementId },
    data: assessmentDraftJson,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 🔥 第二步：获取评估草稿
export function getAssessmentDraft(checkInManagementId) {
  return request({
    url: '/system/management/getAssessmentDraft/' + checkInManagementId,
    method: 'get'
  })
}

// 🔥 第四步：配置入住（保存配置数据到草稿）
export function configureCheckIn(data) {
  return request({
    url: '/system/management/configure',
    method: 'post',
    data: data
  })
}

// 🔥 第五步：签约办理（保存合同信息）
export function signContract(data) {
  return request({
    url: '/system/management/sign',
    method: 'post',
    data: data
  })
}